//用于显示测试计划四个板块的tabPanel
var testDesignTabPanel = Ext.create('Ext.tab.Panel', {
	defaults:{
		layout:'fit'
	},
	items : [ {
		title : '详细信息',
		items : [ testDesignDetailForm ]
	}, {
		title : '测试步骤',
		itemId:'testDesignStepGrid',
		items : [ testDesignStepGrid ]
	}, {
		title : '需求范围',
		itemId:'testDesignTestRequirementGrid',
		items : [ testDesignTestRequirementGrid ]
	}, {
		title : '审核记录',
		itemId:'testDesignCheckLogGrid',
		items : [ testDesignCheckLogGrid ]
	} ],
	buttons : [ {
		itemId : 'testDesignCommitButton',
		text : '保存并提交',
		tooltip : '添加即拿去审核',
		listeners:[{
			click:function(){
				testDesignSave(1);
			}
		}]
	}, {
		itemId : 'testDesignSaveButton',
		text : '保存',
		tooltip : '保存',
		listeners:[{
			click:function(){
				testDesignSave(0);
			}
		}]
	} ],
	listeners:[{
		tabchange:function( tabPanel, newCard, oldCard, eOpts){
			if(newCard.title=='审核记录'){
				var item = testDesignLeftTree.getSelectionModel().getSelected();// 得到被选择的行的数组.
				testDesignCheckLogStore.proxy.url=zuulUrl + '/' + testServiceName + '/testDesignCheck/common/' + item.items[0].data.id;
				testDesignCheckLogStore.reload();
				testDesignTabPanel.down('#testDesignCommitButton').setHidden(true);//审核记录不应该提供这两个按钮
				testDesignTabPanel.down('#testDesignSaveButton').setHidden(true);
			}else{
				if(testDesignCreateOrUpdate==0||testDesignTabPanel.canUpdate){//点击回其他板块的话就要再根据情况看看要不要显示两个按钮
					testDesignTabPanel.down('#testDesignCommitButton').setHidden(false);
					testDesignTabPanel.down('#testDesignSaveButton').setHidden(false);
				}
			}
		}
	}]
});

//用于显示测试计划供选择关联的测试需求的TreeGrid
var testDesignReqTreePanel=Ext.create('Ext.tree.Panel', {
    store:testDesignReqStore,
    rootVisible: false,
    useArrows: true,// 是否用箭头
    header: false,
    listeners: {
    	beforeitemexpand:function(node, eOpts){
    		if(node.data.id!='root')
    			testDesignReqGetChildren(node);
    	},
    	itemdblclick:function( view, record, item, index, e, eOpts){
    		if(!record.data.leaf)
    			Ext.Msg.alert("错误", "请选择叶子节点！");
    		else{
    			var exit=testDesignTestRequirmentStore.getById(record.data.id);
    			if(exit!=null)
    				Ext.Msg.alert("错误", "此测试需求已关联！");
    			else{
    				Ext.Ajax.request({
    		            url: zuulUrl+'/'+testServiceName+'/common/testRequirement/detail/cover/'+record.data.id,
    		            method: 'get',
    		            async: true, // ASYNC 是否异步( TRUE 异步 , FALSE 同步)
    		            success: function (response, opts) {
    		                var obj = Ext.decode(response.responseText);
    		                testDesignTestRequirmentStore.add(obj);
    		            },
    		            failure: function (response, opts) {
    		            	var obj = Ext.decode(response.responseText);
    		            	if(obj.code==401||obj.code==402||obj.code==403)
    		            		Ext.Msg.alert("错误", obj.message);
    		                Ext.Msg.alert("错误", "该功能暂时不可用！");
    		            }
    		        });
    			}
    		}
    	}
    }
});
